package com.yangyang.controller;

import com.github.pagehelper.PageInfo;
import com.yangyang.entity.Account;
import com.yangyang.entity.Finance;
import com.yangyang.entity.QueryVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import com.yangyang.service.FinService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

@Controller
public class FinController {

    @Autowired
    FinService service;


    @RequestMapping("list")
    public String list(HttpServletRequest request, QueryVo vo,
                       @RequestParam(defaultValue = "1") Integer pageNum, @RequestParam(defaultValue = "3") Integer pageSize){
        PageInfo<Finance> p = service.list(vo,pageNum,pageSize);
        request.setAttribute("p",p);
        request.setAttribute("vo",vo);
        return "list";
    }

    @RequestMapping("toadd")
    public String toadd(){
        return "add";
    }

    @RequestMapping("add")
    public String add(Finance finance){
        int i = service.add(finance);
        System.out.println("添加的对象"+finance);
        return "redirect:list";
    }

    @RequestMapping("getAccountByName")
    @ResponseBody
    public Account getAccountByName(String name){
        Account accountByName = service.getAccountByName(name);
        return accountByName;
    }

}
